<?php
namespace app\model;

use think\Model;

use think\Db;

class AppointmentModel extends Model
{
    protected $table = 'appointment';
    protected $resultSetType = 'collection';


    public static function todayCount( $companyid ){

        $starttime = strtotime(date("Y-m-d"),time());
        $endtime = $starttime+86400;
        $sql = 'SELECT count(*) as count FROM `meeting` WHERE appointment_companyid='.$companyid.' AND status=3 AND appointmentid IN (
            SELECT id FROM `appointment` where visittime>='.$starttime.' AND visittime<'.$endtime.')';

        $result = DB::query($sql);

        return $result[0]['count'];
    }

    // if($this->user->roleid == Config::get('ROLE_COMPANY_MANAGER') || $this->user->roleid == Config::get('ROLE_SECURITY_MANAGER')){
    //     $appointmentList = AppointmentModel::field('appointment.*,user.name as name,company.name as cname')
    //                                         ->join('user','user.id=appointment.uid','left')
    //                                         ->join('company','company.id=appointment.companyid','left')
    //                                         ->where($where)
    //                                         ->where('appointment.companyid','eq',$this->user->companyid)
    //                                         ->page($page,$pagesize)->select();
    //     $total = AppointmentModel::where($where)->where('companyid','eq',$this->user->companyid)->count();
    // }elseif($this->user->roleid == Config::get('ROLE_DEPARTMENT_MANAGER')){
    //     $appointmentList = AppointmentModel::field('appointment.*,user.name as name,company.name as cname')
    //                                         ->join('user','user.id=appointment.uid','left')
    //                                         ->join('company','company.id=appointment.companyid','left')
    //                                         ->where($where)
    //                                         ->where('appointment.companyid','eq',$this->user->companyid)
    //                                         ->where('appointment.deptid','eq',$this->user->deptid)
    //                                         ->page($page,$pagesize)->select();
    //     $total = AppointmentModel::where($where)->where('companyid','eq',$this->user->companyid)->count();
    // }else{
    //     $appointmentList = AppointmentModel::field('appointment.*,user.name as name,company.name as cname')
    //                                         ->join('user','user.id=appointment.uid','left')
    //                                         ->join('company','company.id=appointment.companyid','left')
    //                                         ->where($where)->where('uid','eq',$this->user->id)->page($page,$pagesize)->select();
    //     $total = AppointmentModel::where($where)->where('uid','eq',$this->user->id)->count();
    // }

}
